package com.huaxin.hxmoduleworkorder.feignclients.impl;

import com.huaxin.feignclient.device.DeviceClient;
import com.huaxin.feignclient.device.models.ElectricalRoom;
import com.huaxin.feignclient.device.models.SwitchCabinet;
import com.huaxin.feignclient.models.ResponseCode;
import com.huaxin.hxmoduleworkorder.feignclients.DeviceFeignService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DeviceFeignServiceImpl implements DeviceFeignService {
    private final DeviceClient deviceClient;

    @Override
    public List<SwitchCabinet> cabinetListByIds(List<String> ids) {
        com.huaxin.feignclient.models.ResponseResult<List<SwitchCabinet>> result = deviceClient.cabinetListByIds(ids);
        if (result.getCode() != ResponseCode.SUCCESS.getCode() || result.getData() == null) {
            return List.of();
        }
        return (List<SwitchCabinet>) result.getData();
    }

    @Override
    public List<SwitchCabinet> cabinetListByOrgId(String orgId) {
        com.huaxin.feignclient.models.ResponseResult<List<SwitchCabinet>> result = deviceClient.cabinetListByOrgId(orgId);
        if (result.getCode() != ResponseCode.SUCCESS.getCode() || result.getData() == null) {
            return List.of();
        }
        return (List<SwitchCabinet>) result.getData();
    }

    @Override
    public List<SwitchCabinet> cabinetListByOrgIds(List<String> orgIds) {
        com.huaxin.feignclient.models.ResponseResult<List<SwitchCabinet>> result = deviceClient.cabinetListByOrgIds(orgIds);
        if (result.getCode() != ResponseCode.SUCCESS.getCode() || result.getData() == null) {
            return List.of();
        }
        return (List<SwitchCabinet>) result.getData();
    }

    @Override
    public List<SwitchCabinet> cabinetListByFamilyId(String familyId) {
        com.huaxin.feignclient.models.ResponseResult<List<SwitchCabinet>> result = deviceClient.cabinetListByFamilyId(familyId);
        if (result.getCode() != ResponseCode.SUCCESS.getCode() || result.getData() == null) {
            return List.of();
        }
        return (List<SwitchCabinet>) result.getData();
    }

    @Override
    public List<SwitchCabinet> cabinetListByFamilyIds(List<String> familyIds) {
        com.huaxin.feignclient.models.ResponseResult<List<SwitchCabinet>> result = deviceClient.cabinetListByFamilyIds(familyIds);
        if (result.getCode() != ResponseCode.SUCCESS.getCode() || result.getData() == null) {
            return List.of();
        }
        return result.getData();
    }

    @Override
    public List<ElectricalRoom> electricianRoomListByIds(List<String> ids) {
        com.huaxin.feignclient.models.ResponseResult<List<ElectricalRoom>> result = deviceClient.electricalRoomListByIds(ids);
        if (result.getCode() != ResponseCode.SUCCESS.getCode() || result.getData() == null) {
            return List.of();
        }
        return result.getData();
    }
}
